﻿using UnityEngine;

namespace winS.Unity
{
    /// <summary>
    /// 提供对运行设备的管理
    /// </summary>
    public class Device
    {
        /// <summary>
        /// 显示器
        /// </summary>
        public Display display { get; private set; } = new Display();

        /// <summary>
        /// 表示当前所运行的显示器硬件信息
        /// </summary>
        public class Display
        {
            /// <summary>
            /// 显示器宽高比
            /// </summary>
            public float aspect { get; private set; }

            /// <summary>
            /// 显示器分辨率
            /// </summary>
            public Vector2Int resolution { get; private set; }

            internal void UpdateInfo()
            {
                //手动更新信息, 因为可能从主线程外或编辑器环境下访问而导致构造函数在主线程外调用
                resolution = new Vector2Int(UnityEngine.Display.main.systemWidth, UnityEngine.Display.main.systemHeight);
                aspect = resolution.x / resolution.y;
            }
        }
    }
}